package skeleton;

import java.awt.*;
import javax.swing.*;

import util.Pair;

//import com.sun.awt.AWTUtilities;

public class GBoard extends JFrame {
	public static final long serialVersionUID = 6638276987305608028L;
	BoardPanel mainBoard;
//	public JLabel boardLabel;
	public Image board;
	public Player father;
//	public int 
	
	
//	BufferedImage bufferedImage;
	
	public GBoard() {
		super();
//		ImageIcon imageIcon = new ImageIcon(boardFile);
//		bufferedImage=new BufferedImage(imageIcon.getIconHeight(),imageIcon.getIconWidth(),BufferedImage.TYPE_INT_RGB);
		initGUI();
	}
	
	public void setColor(int color) {mainBoard.setColor(color);}
	public void setGameover() {mainBoard.setGameover();}
	public void setChess(int x, int y) {
		mainBoard.machinePlay(y, x);
	}
	public void initGUI() {
//		addWindowListener(new WindowAdapter() {});
//		Toolkit toolkit = Toolkit.getDefaultToolkit();
//
//		String boardFile = "res" + File.separatorChar + "board.jpg";
//		board = toolkit.getImage(boardFile);
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		mainBoard = new BoardPanel();
		mainBoard.father = this;
		this.setMinimumSize(new Dimension(355, 376));
		setLayout(new BorderLayout());
		getContentPane().add(mainBoard, BorderLayout.CENTER);
		
//		this.add(mainBoard);
		this.setVisible(true);
		this.setResizable(false);
	}
	
	public Pair getLastPos() {return mainBoard.getLastPos();}

	public void chessed() {
		father.chessed();
	}
	
//	public void paint(Graphics g) {
//		Graphics2D g2 = (Graphics2D)g;
//		g2.drawImage(board, 0, 0, null);
//		System.out.println(draw);
//		if(draw) {
//			if (curColor == BLACK) {
//				System.out.println("@####1");
//				g2.drawImage(black, xAxis+OFFSET_X, yAxis+OFFSET_Y, null);
//			}
//			else if (curColor == WHITE) {
//				System.out.println("@####2");
//				g2.drawImage(white, xAxis+OFFSET_X, yAxis+OFFSET_Y, null);
//			}
//		}
//	}
	
//	
//	class MyMouseListener extends MouseAdapter {
//		@Override
//		public void mouseClicked(MouseEvent e) {
//			if (gameover) return;
////			Graphics graphics = board.getGraphics();
//			Graphics2D graphics=(Graphics2D)bufferedImage.getGraphics();
//			int x = e.getX() , y = e.getY() ;
//			System.out.println(x +" " + y);
//			if (invalidPos(x, y)) return;
////			drawOnPos(graphics, curColor, x, y);
//			this.x = x;
//			this.y = y;
//			repaint();
//			boardLabel.setIcon(new ImageIcon(board));
//		}
//		
////		public void drawOnPos(Graphics g, int myColor, int x, int y) {
////			System.out.println("@####");
////			if (curColor == BLACK) {
////				System.out.println("@####1");
//////				g.drawLine(x, y, x+50, y+50);
////				g.drawImage(black, x+OFFSET_X, y+OFFSET_Y, null);
////			}
////			else if (curColor == WHITE) {
////				System.out.println("@####2");
////				g.drawImage(white, x+OFFSET_X, y+OFFSET_Y, null);
////			}
////		}
//
//		

}


